<?php


namespace Drupal\shusy_category_rebate_product\ViewsController\handler\filter;


use Drupal\shusy_category\Entity\ShusyCategory;
use views_handler_filter_many_to_one;

class ShusyCategoryRebateProductCategoriesViewsFilter extends views_handler_filter_many_to_one {

  public function get_value_options() {
    if (!isset($this->value_options)) {
      $this->value_title = "分类";

      $options = [];
      $parent = 0;
      $children = db_query('SELECT id, name, weight, parent,status
                      FROM {shusy_category}
                      WHERE (parent = :parent)
                      ORDER BY weight ASC', [':parent' => $parent]);
      foreach ($children as $child) {
        $children2 = db_query('SELECT id, name, weight, parent,status
                      FROM {shusy_category}
                      WHERE (parent = :parent)
                      ORDER BY weight ASC', [':parent' => $child->id]);
        $options[$child->name] = [];
        foreach ($children2 as $child2) {
          $children3 = db_query('SELECT id, name, weight, parent,status
                      FROM {shusy_category}
                      WHERE (parent = :parent)
                      ORDER BY weight ASC', [':parent' => $child2->id]);
          foreach ($children3 as $child3) {
            $options["{$child->name}|{$child2->name}"][$child3->id] = $child3->name;
          }
        }
      }

      $this->value_options = $options;
    }
  }

}
